package com.mlz.mlzmall.ui.activity.act.personal.userLogin;

import android.content.Context;
import android.util.Log;


import com.mlz.mlzmall.ui.utils.mlz.URL;
import com.mlz.mlzmall.ui.utils.util.ACache;

import org.springframework.web.client.RestTemplate;

/**
 * Created by Administrator on 2016/2/2.
 */
public class HttpUtlis {
    private RestTemplate restTemplate;
    private Context context;


    public HttpUtlis(Context context) {
        this.context = context;
    }

    public void saveSessionKey(final RestTemplate restTemplate) {
        new Thread(new Runnable() {
            @Override
            public void run() {

                GetSession urlSession = restTemplate.getForObject(URL.SESSION.GET, GetSession.class);
                String sessionKey = urlSession.getData().getSessionKey();
                Log.i("info", "sessionKey=" + sessionKey);

                //  把sessionKey 字符串保存到手机内部存储卡
                ACache mCache = ACache.get(context);
                // 存放时间设定为1天,默认数量为1，更新会覆盖前面的值
                if (sessionKey != null) {
                    mCache.clear();
                    mCache.put("sessionKeyAuth", sessionKey, ACache.TIME_DAY);
                }
            }

        }).start();
    }
}
